var UserPageRecommend = {

    init:function(_path){
        this.path = _path;
        this.inner = $("#like-body");
        this.pageCount = 10;
        this.page = 0;
        this.changePage();
        this.addListener();
    },
    changePage: function(){
        $.get(this.path+"/userBookTag/userBookIndex.do",{
            "start" : this.page * this.pageCount,
            "count" : this.pageCount
        },function(data, status){
            console.log(data);
            if(status === 'success' && data.code === 200){
                UserPageRecommend.innerData(data.data);
                UserPageRecommend.changeParam(data);
            }else{
                console.log("获取数据失败");
            }
        });
    },
    // <div class="book-wrap">
    //     <div class="book thumbnail" data-toggle="tooltip" data-placement="left" title="444">
    //         <img src="https://img3.doubanio.com/view/subject/s/public/s4364071.jpg" onerror="this.src='${path}/images/default-book.png'" />
    //         <p>デュラララ!!×7 </p>
    //     </div>
    // </div>
    createSimpleBook:function(simple){
        return $("<div></div>").addClass("book-wrap").append($("<div></div>").addClass("book").addClass("thumbnail")
            .attr("data-toggle", "tooltip").attr("data-placement","left").attr("title",simple.title+" "+simple.subtitle)
            .append($("<img src=''/>").attr("src",simple.smallImage).attr("onerror",this.path+"/images/default-book.png"))
            .append($("<p></p>").text(simple.title)).attr("bookid",simple.id).click(function(){
                window.open(UserPageRecommend.path+"/page/book/id/"+$(this).attr("bookid")+".do");
            }));
    },
    innerData:function(data){
        this.inner.html('');
        data.forEach(function(simple){
            UserPageRecommend.inner.append(UserPageRecommend.createSimpleBook(simple));
        });
    },
    changeParam(data){
        this.page++;
        if(this.page >= Math.floor(data.total/this.pageCount)){
            this.page = 0;
        }
    },
    addListener:function(){
        $("#change").click(function(){
            UserPageRecommend.changePage();
        });
    }
};